package com.xht.controller;

import com.xht.domain.ResponseResult;
import com.xht.service.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/article")
public class ArticleController {

    private static final Logger log = LoggerFactory.getLogger(ArticleController.class);
    @Autowired
    public ArticleService articleService;


    /**
     *首页中查询热点文章
     */
    @GetMapping("/hotArticleList")
    public ResponseResult hotArticleList(){
        /*
            查询热门文章  封装成ResponseResult返回
         */

       return  articleService.hostArticleList();
    }

    /**
     * 查询文章，若有类型则查询 该类型下的文章
     * @param pageNum
     * @param pageSize
     * @param categoryId
     * @return
     */
    @GetMapping("/articleList")
    public ResponseResult articleList(Integer pageNum,Integer pageSize,Long categoryId){
        return articleService.articleList(pageNum,pageSize,categoryId);
    }

    /**
     * 查询详情文章全内容
     *  获取 路径形式的参数(/article/1)需要添加 注释 @PathVariable
     */
    @GetMapping("/{id}")
    public ResponseResult getArticleDetail(@PathVariable Long id){

        return articleService.getArticleDetail(id);
    }

    @PutMapping("/updateViewCount/{id}")
    public ResponseResult updateViewCount(@PathVariable("id") Long id) {
        return articleService.updateViewCount(id);
    }


//    /**
//     * test
//     * 添加数据
//     */
//    @PostMapping("/add")
//    public void add(){
//        articleService.add();
//    }
}
